package net.scribblemedia.candle.data.pattern;

import static net.scribblemedia.candle.util.ScribbleCollectionUtils.firstElement;
import static net.scribblemedia.candle.util.ScribbleCollectionUtils.lastElement;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;

import org.encog.ml.data.market.loader.LoadedMarketData;

public class PatternWindow {
	private static final String YEAR_MONTH_DAY = "yyyy/MM/dd";
	private Collection<LoadedMarketData> tailData;
	private Collection<LoadedMarketData> noseData;
	private String symbol;

	public PatternWindow(String symbol, Collection<LoadedMarketData> tailData, Collection<LoadedMarketData> noseData) {
		this.symbol = symbol;
		this.tailData = tailData;
		this.noseData = noseData;
	}

	private String dateFrom(LoadedMarketData marketData) {
		if (marketData == null) {
			return null;
		}
		
		return new SimpleDateFormat(YEAR_MONTH_DAY).format(marketData.getWhen());
	}

	public Collection<LoadedMarketData> getTailData() {
		return tailData;
	}

	public void setTailData(Collection<LoadedMarketData> tailData) {
		this.tailData = tailData;
	}

	public Collection<LoadedMarketData> getNoseData() {
		return noseData;
	}
	
	public void setNoseData(Collection<LoadedMarketData> noseData) {
		this.noseData = noseData;
	}

	@Override
	public String toString() {
		return "Stock symbol=" + symbol + 
				", Tail start=" + dateFrom(firstElement(getTailData())) + 
				", Tail end=" + dateFrom(lastElement(new ArrayList<LoadedMarketData>(getTailData()))) +
				", Nose start=" + dateFrom(firstElement(getNoseData())) + 
				", Nose end=" + dateFrom(lastElement(new ArrayList<LoadedMarketData>(getNoseData())));
	}

	public String getSymbol() {
		return symbol;
	}
}
